import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.util.Scanner;

public class iuer {
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.util.Scanner;

    public class swesdf {
import java.io.IOException;
import java.net.*;
import java.util.Scanner;

        public class UdpEchoClient {
            DatagramSocket socket = null;
            private String serverIp;
            private int serverPort;

            public UdpEchoClient( int serverPort) throws SocketException {
                this.socket = new DatagramSocket();
                this.serverIp = serverIp;
                this.serverPort = serverPort;
            }
            public void start() throws IOException {
                Scanner scanner = new Scanner(System.in);
                System.out.println("客户端启动");
                while(true){
                    System.out.println("->");
                    String request = scanner.next();
                    DatagramPacket requestPacket = new DatagramPacket(request.getBytes(),0,
                            request.getBytes().length, InetAddress.getByName(serverIp),serverPort);
                    socket.send(requestPacket);
                    DatagramPacket responePacket = new DatagramPacket(new byte[4096],4096);
                    socket.receive(responePacket);
                    String respond = new String(responePacket.getData());
                    System.out.println(respond);
                }
            }

            public static void main(String[] args) throws IOException {
                UdpEchoClient udpEchoClient = new UdpEchoClient(9001);
                udpEchoClient.start();
            }
        }

    }

}
